home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / conhlp.arc / CONHELP.C next >
Text File  |  1988-11-23  |  8KB  |  258 lines

  1. #include    <nvt.h>
  2. #include    <ndt.h>
  3. #include    <string.h>
  4. #include    "conhelp.h"
  5.  
  6. extern int    Keyword, MyHeaderSegment;
  7. int            machineType, handle, serverNumber, currentDrive, index, scrIndex;
  8. int            ImStillUp, ccode, loginError, mainProcessID;
  9. char        inputChar, serverName[48], buffer[14], readBuffer[MAX_BUFFER_SIZE+1];
  10. char        *localPath;
  11.  
  12. main()
  13. {
  14.     ImStillUp = 1;
  15.     ccode = loginError = 0;
  16.     mainProcessID = GetProcessID();
  17.     if ( ( machineType = VGetFileServerName( serverName ) ) == FILESERVER )
  18.     {
  19.         ccode = VAPAttachToFileServer( serverName, &serverNumber );
  20.         switch ( ccode )
  21.         {
  22.             case 0:
  23.                 SetPreferredConnectionID( serverNumber );
  24.                 break;
  25.             case 1:
  26.                 VAPMapFileServerNameToNumber( serverName, &serverNumber );
  27.                 SetPreferredConnectionID( serverNumber );
  28.                 break;
  29.             default:
  30.                 VPrintString( -1, -1, "Unable to attach to Server ", -1 );
  31.                 VPrintString( -1, -1, serverName, -1 );
  32.                 VPrintString( -1, -1, ".\n\r", -1 );
  33.                 VPrintString( -1, -1, "Console Help VAP not loaded.\n\r", -1 );
  34.                 ImStillUp = 0;
  35.                 break;
  36.         } 
  37.         if ( ImStillUp )
  38.         {
  39.             if ( ccode = LoginToFileServer( "GUEST", 1, NULL ) )
  40.             {
  41.                 loginError = 1;
  42.                 switch ( ccode )
  43.                 {
  44.                     case 0xFC:
  45.                         VPrintString( -1, -1, "User GUEST must be defined on Server ", -1 );
  46.                         VPrintString( -1, -1, serverName, -1 );
  47.                         VPrintString( -1, -1, " to use the Console Help VAP.\n\r", -1 );
  48.                         ImStillUp = 0;
  49.                         break;
  50.                     case 0xDA:
  51.                         VPrintString( -1, -1, "Unauthorized login time for user GUEST on server ", -1 );
  52.                         VPrintString( -1, -1, serverName, -1 );
  53.                         VPrintString( -1, -1, ".\n\r", -1 );
  54.                         VPrintString( -1, -1, "Modify user GUEST's allowed login times with the SYSCON utility.\n\r", -1 );
  55.                         VPrintString( -1, -1, "(Note: You must be a SUPERVISOR or supervisor equivalent to modify login times)\n\r", -1 );
  56.                         ImStillUp = 0;
  57.                         break;
  58.                     case 0xDB:
  59.                         VPrintString( -1, -1, "Unauthorized login station for user GUEST on server ", -1 );
  60.                         VPrintString( -1, -1, serverName, -1 );
  61.                         VPrintString( -1, -1, ".\n\r", -1 );
  62.                         VPrintString( -1, -1, "Modify user GUEST's allowed login stations with the SYSCON utility.\n\r", -1 );
  63.                         VPrintString( -1, -1, "(Note: You must be a SUPERVISOR or supervisor equivalent to modify login stations)\n\r", -1 );
  64.                         ImStillUp = 0;
  65.                         break;
  66.                     default:
  67.                         VPrintString( -1, -1, "Error ", -1 );
  68.                         itoa( ccode, buffer, 10 );
  69.                         VPrintString( -1, -1, buffer, -1 );
  70.                         VPrintString( -1, -1, "h occurred while attempting to login to Server ", -1 );
  71.                         VPrintString( -1, -1, serverName, -1 );
  72.                         VPrintString( -1, -1, ".\n\r", -1 );
  73.                         ImStillUp = 0;
  74.                         break;
  75.                 }
  76.             }
  77.         }
  78.         if ( ImStillUp )
  79.         {
  80.             if ( ccode = VOpen( "SYS:PUBLIC/CONHELP.DAT", 0x40, &handle ) ) 
  81.             {
  82.                 switch ( ccode )
  83.                 {
  84.                        case 0xFF:
  85.                         if ( !loginError )
  86.                             VPrintString( -1, -1, "CONHELP.DAT file not found in SYS:PUBLIC.\n\r", -1 );
  87.                         ImStillUp = 0;
  88.                         break;
  89.                     case 0x93:
  90.                     case 0x94:
  91.                     case 0x82:
  92.                         VPrintString( -1, -1, "Not enough privileges to open CONHELP.DAT.\n\r", -1 );
  93.                         VPrintString( -1, -1, "Check the EFFECTIVE rights of user GUEST in SYS:PUBLIC.\n\r", -1 );
  94.                         VPrintString( -1, -1, "User GUEST must have at least R(ead) O(pen) S(earch) rights.\n\r", -1 );
  95.                         ImStillUp = 0;
  96.                         break;
  97.                     default:
  98.                         VPrintString( -1, -1, "Error occurred opening SYS:PUBLIC/CONHELP.DAT: ", -1 );
  99.                         itoa( ccode, buffer, 10 );
  100.                         VPrintString( -1, -1, buffer, -1 );
  101.                         VPrintString( -1, -1, "h \n\r", -1 );
  102.                         ImStillUp = 0;
  103.                         break;
  104.                 } 
  105.             } 
  106.         }
  107.     }
  108.     if ( machineType == BRIDGE )
  109.     {
  110.         VSetPassThroughMode( 1 );
  111.         if ( ( currentDrive = VGetCurrentDisk() ) != 0xFF )
  112.         {
  113.             currentDrive += 65;  /* convert it to an ascii drive letter value */
  114.             buffer[0] = currentDrive;
  115.             buffer[1] = 0x00;
  116.             localPath = strcat( buffer, ":\\CONHELP.DAT" );
  117.          }
  118.          else
  119.          {
  120.              VPrintString( -1, -1, "Error occurred during GetCurrentDisk.\n\r", -1 );
  121.             ImStillUp = 0;
  122.            }
  123.         if ( ccode = VOpen( localPath, 0x40, &handle ) ) 
  124.         {
  125.                switch ( ccode )
  126.             {
  127.                    case 0x02:
  128.                     VPrintString( -1, -1, localPath, -1 );
  129.                     VPrintString( -1, -1, "-file not found.\n\r", -1 );
  130.                     break;
  131.                 case 0x03:
  132.                     VPrintString( -1, -1, localPath, -1 );
  133.                     VPrintString( -1, -1, "-path not found.\n\r", -1 );
  134.                     break;
  135.                 default:
  136.                     VPrintString( -1, -1, "Error occurred opening ", -1 );
  137.                     VPrintString( -1, -1, localPath, -1 );
  138.                     VPrintString( -1, -1, ": ", -1 );
  139.                     itoa( ccode, buffer, 10 );
  140.                     VPrintString( -1, -1, buffer, -1 );
  141.                     VPrintString( -1, -1, "h \n\r", -1 );
  142.                     break;
  143.             }
  144.         } 
  145.         VSetPassThroughMode( 0 );
  146.     }
  147.     VInitializationComplete();
  148.     while ( 1 )
  149.     {
  150.         VSleepProcess();
  151.         if ( ( index >= 0 ) && ( index <= 7 ) )
  152.         {
  153.             if ( MenuList[index].menuPtr != NULL )
  154.             {
  155.                 ClearScreen();
  156.                 PrintArray( MenuList[index].menuPtr, MenuList[index].menuLength );
  157.                 VSleepProcess();
  158.                 scrIndex = toupper( inputChar ) - 'A';
  159.                 if ( ( scrIndex >= 0 && scrIndex <= ( MAX_MENU_ITEMS-1 ) )
  160.                     && ( MenuList[index].Screen[scrIndex].screenPtr != NULL ) )
  161.                 {
  162.                     ClearScreen();
  163.                     PrintArray( MenuList[index].Screen[scrIndex].screenPtr,
  164.                                 MenuList[index].Screen[scrIndex].screenLength );
  165.                 }
  166.             }
  167.         }
  168.         else
  169.             if ( index == 8 )
  170.             {
  171.                 ClearScreen();
  172.                 PrintArray( MAINHELPOFF, MAINHELPLEN );
  173.             }
  174.             else
  175.                 VPrintString( -1, -1, "No help for specified command.\r\n", -1 );
  176.     } 
  177.  
  178. ConsoleHandler()
  179. {
  180.     if ( ImStillUp )
  181.     {
  182.         ccode = GetScreenMode();
  183.         switch ( ccode )
  184.         {
  185.         case 0:
  186.             SetScreenMode( MyHeaderSegment );
  187.             break;
  188.         case 0xFFFF:
  189.             SetScreenMode( MyHeaderSegment );
  190.             break;
  191.            default:
  192.             break;
  193.         }
  194.  
  195.          if ( ( ccode != MyHeaderSegment ) && ( ccode > 0 ) )
  196.         {
  197.             ConsoleDisplay( "Help is disabled until another VAP releases screen control." );
  198.             return( 0 );
  199.         }
  200.         else
  201.         {
  202.             inputChar = '\0';
  203.             index = Keyword / 2;
  204.             WakeUpProcess( mainProcessID );
  205.             if ( ( index  >=0 ) && ( index <=7 ) )
  206.             {
  207.                 VInString( MenuList[index].menuLength, 2, ">", &inputChar, 1 );
  208.                 VPrintString( -1, -1, &inputChar, 1 );
  209.                 VPrintString( -1, -1, "\n\r", -1 );
  210.                 WakeUpProcess( mainProcessID );
  211.             }
  212.         }
  213.     }
  214.     return( 0 );
  215. }
  216.  
  217. DownHandler()
  218. {
  219.     ImStillUp = 0;
  220.     ConsoleDisplay( "Console Help VAP is down." );
  221.     return( 0 );
  222. }
  223.  
  224. PrintArray( p, numRecords )
  225. long p;
  226. unsigned numRecords;
  227. {
  228.     int            i;
  229.     long        newPointer;
  230.     unsigned    bytesRead=0;
  231.  
  232.     if ( numRecords <= MAX_RECORDS )
  233.     {
  234.         memset( readBuffer, '\0', MAX_BUFFER_SIZE );
  235.         if ( machineType == BRIDGE )
  236.             VSetPassThroughMode( 1 );
  237.         newPointer = VSeek( handle, p, BEG_FILE ); 
  238.         if ( ( bytesRead = VRead( handle, readBuffer, ( RECORD_SIZE*numRecords ) ) ) == 0 )
  239.             {
  240.                 VPrintString( -1, -1, "Error reading CONHELP.DAT.\n\r", -1 );
  241.                 VPrintString( -1, -1, "Number of bytes successfully read: ", -1 );
  242.                 itoa( bytesRead, buffer, 10 );
  243.                 VPrintString( -1, -1, buffer, -1 );
  244.                 VPrintString( -1, -1, "\n\r", -1);
  245.                  ImStillUp = 0; 
  246.         }
  247.         if ( machineType == BRIDGE )
  248.             VSetPassThroughMode( 0 );
  249.         if ( ImStillUp )
  250.         {
  251.             readBuffer[bytesRead] = '\0';
  252.             for ( i = 0;i < numRecords;i++ )
  253.                 VPrintString( -1, -1, &readBuffer[ ( i*RECORD_SIZE ) ], RECORD_SIZE );
  254.         }
  255.     }
  256. }
  257.